package com.d3works.apps.businessproduction.service;

import com.d3works.apps.base.service.UnitConversionService;
import com.d3works.apps.production.db.ProductionOrder;
import com.d3works.apps.production.db.repo.ProductionOrderRepository;
import com.d3works.apps.production.service.app.AppProductionService;
import com.d3works.apps.production.service.productionorder.ProductionOrderSaleOrderServiceImpl;
import com.d3works.apps.production.service.productionorder.ProductionOrderService;
import com.d3works.apps.sale.db.SaleOrder;
import com.d3works.exception.D3worksException;
import com.google.inject.Inject;

public class ProductionOrderSaleOrderServiceBusinessImpl
    extends ProductionOrderSaleOrderServiceImpl {

  @Inject
  public ProductionOrderSaleOrderServiceBusinessImpl(
      UnitConversionService unitConversionService,
      ProductionOrderService productionOrderService,
      ProductionOrderRepository productionOrderRepo,
      AppProductionService appProductionService) {
    super(unitConversionService, productionOrderService, productionOrderRepo, appProductionService);
  }

  @Override
  protected ProductionOrder createProductionOrder(SaleOrder saleOrder) throws D3worksException {

    ProductionOrder productionOrder = super.createProductionOrder(saleOrder);

    if (appProductionService.isApp("production")
        && appProductionService.getAppProduction().getManageBusinessProduction()) {
      productionOrder.setProject(saleOrder.getProject());
    }
    return productionOrder;
  }
}
